 // 阻止网页中文字的默认选中行为
 var body = document.querySelector('body')
 body.onselectstart = function () {
     return false
 }
 // 顶部更换城市部分
 var position = document.querySelector('.position span')
 var position_down = document.querySelector('.position_down')
 var arr = ['北京', '上海', '天津', '重庆', '河北', '山西', '河南', '辽宁', '吉林', '黑龙江', '内蒙古', '江苏', '山东', '安徽', '浙江', '福建', '湖北', '湖南 ', '广东', '广西', '江西', '四川', '河南', '贵州', '云南', '西藏', '陕西', '甘肃', '青海', '宁夏', '新疆', '港澳', '台湾', '钓鱼岛', '海外']
 document.querySelector('topNav_right li')
 //鼠标移入显示下拉框
 position.onmouseover = function () {
     position_down.style.display = 'block'
     position.style.cursor = 'pointer'
     position.parentElement.style.backgroundColor = 'white'
     var str = ''
     for (var i = 0; i < arr.length; i++) {
         str += `
         <li><a>${arr[i]}</a></li>
         `
     }
     position_down.innerHTML = str
     var lis = document.querySelectorAll('.position_down a')
     for (var i = 0; i < lis.length; i++) {
         if (lis[i].innerText === position.innerText) {
             lis[i].style.backgroundColor = 'red'
         }
     }
 }
 //鼠标移出下拉框消失
 var timerId
 position.onmouseout = position_down.onmouseout = function () {
     timerId = setTimeout(() => {
         position_down.style.display = 'none'
         position.parentElement.style.backgroundColor = '#E3E4E5'
     }, 100)
 }
 //鼠标移动到下拉框中选中的内容颜色改变，并显示在页面的定位中   
 position_down.onmouseover = function () {
     var lis = document.querySelectorAll('.position_down a')
     clearTimeout(timerId)
     position_down.style.display = 'block'
     position_down.onclick = function () {
         var e = window.event
         var target = e.target || e.srcElement
         if (target.tagName === 'A') {
             position.innerText = target.innerText
             for (var i = 0; i < lis.length; i++) {
                 lis[i].style.backgroundColor = 'white'
                 lis[i].style.color = '#ccc'
             }
             target.style.backgroundColor = 'red'
             target.style.color = 'white'
         }
     }
 }
 // 我的商城下拉部分
 var myStore = document.querySelector('.myStore');
 var brr = ['待处理订单', '我的问答', '返修退换货', '我的关注', '降价商品'];
 var crr = ['我的豆豆', '我的优惠券', '我的白条', '我的理财',]
 myStore.previousElementSibling.onmouseover = function () {
     myStore.style.display = 'block'
     myStore.previousElementSibling.parentElement.style.backgroundColor = 'white'
     var str = '<ul>'
     for (var i = 0; i < brr.length; i++) {
         str += `
         <li><a>${brr[i]}</a></li>
         `
     }
     str += '</ul><ul>'
     for (var i = 0; i < crr.length; i++) {
         str += `
         <li><a>${crr[i]}</a></li>
         `
     }
     str += `</str>`
     myStore.innerHTML = str
 }
 var timerId1
 myStore.previousElementSibling.onmouseout = myStore.onmouseout = function () {
     timerId1 = setTimeout(() => {
         myStore.style.display = 'none'
         myStore.previousElementSibling.parentElement.style.backgroundColor = '#E3E4E5'
     }, 100)
 }
 myStore.onmouseover = function () {
     clearTimeout(timerId1)
     myStore.style.display = 'block'
 }

 //企业采购
 var enterprise = document.querySelector('.enterprise');
 var drr = ['企业购', '商用场景馆', '工业品', '礼品卡'];
 enterprise.previousElementSibling.onmouseover = function () {
     enterprise.style.display = 'block'
     enterprise.previousElementSibling.parentElement.style.background = 'white'
     var str = '<ul>'
     for (var i = 0; i < drr.length; i++) {
         str += `
         <li><a>${drr[i]}</a></li>
         `
     }
     str += '</ul>'
     enterprise.innerHTML = str
 }
 var timerId1
 enterprise.previousElementSibling.onmouseout = enterprise.onmouseout = function () {
     timerId1 = setTimeout(() => {
         enterprise.style.display = 'none'
         enterprise.previousElementSibling.parentElement.style.background = '#E3E4E5'
     }, 100)
 }
 enterprise.onmouseover = function () {
     clearTimeout(timerId1)
     enterprise.style.display = 'block'
 }


 // 客户服务
 var server = document.querySelector('.server');
 var err = ['帮助中心', '售后服务', '在线客服', '意见建议', '电话客服', '客服邮箱', '金融咨询', '全球售客服', '企业客服'];
 var frr = ['合作招商', '成长中心', '商家后台', '麦工作台', '商家帮助', '规则平台'];
 server.previousElementSibling.onmouseover = function () {
     server.style.display = 'block'
     server.previousElementSibling.parentElement.style.background = 'white'
     var str = '<ul><div class="serverTitle">客户</div>'
     for (var i = 0; i < err.length; i++) {
         str += `
         <li><a>${err[i]}</a></li>
         `
     }
     str += '</ul><ul><div class="clear serverTitle">商户</div>'
     for (var i = 0; i < frr.length; i++) {
         str += `
         <li><a>${frr[i]}</a></li>
         `
     }
     server.innerHTML = str
 }
 var timerId1
 server.previousElementSibling.onmouseout = server.onmouseout = function () {
     timerId1 = setTimeout(() => {
         server.style.display = 'none'
         server.previousElementSibling.parentElement.style.background = '#E3E4E5'
     }, 100)
 }
 server.onmouseover = function () {
     clearTimeout(timerId1)
     server.style.display = 'block'
 }

 // 网站导航
 var webnav = document.querySelector('.webnav');
 var featureData = ['新品首发', '金融', '全球售', '国际站', '会员', '台湾售', '俄语站', '装机大师', '港澳售', '优惠券', '秒杀', '内购', '印尼站', '陪伴计划', '出海招商', '拍拍二手', '买什么'];
 var industryData = ['手机', '只能数码', '电脑办公', '家用电器', '小家', '服饰', '生鲜', '家装城市', '母婴', '食品', '农资频道', '整车', '图书', '劳动防护'];
 var lifeData = ['众筹', '白条', '金融 App', '小金库', '理财', '话费', '水电煤', '彩票', '旅行', '机票酒店', '电影票', '游戏', '拍拍回收'];
 var moreData = ['合作招商', '通信', 'E卡', '企业采购', '市场服务', '办公生活馆', '校园加盟', '社区', '游戏社区', '知识产权，关于我们'];
 webnav.previousElementSibling.onmouseover = function () {
     webnav.style.display = 'block'
     webnav.previousElementSibling.parentElement.style.background = 'white'
     var str = '<ul><div class="webnavTitle">特色主题</div>'
     for (var i = 0; i < featureData.length; i++) {
         str += `
         <li><a>${featureData[i]}</a></li>
         `
     }
     str += '</ul><ul><div class="clear webnavTitle">行业频道</div>'
     for (var i = 0; i < industryData.length; i++) {
         str += `
         <li><a>${industryData[i]}</a></li>
         `
     }
     str += '</ul><ul><div class="clear webnavTitle">生活服务</div>'
     for (var i = 0; i < lifeData.length; i++) {
         str += `
         <li><a>${lifeData[i]}</a></li>
         `
     }
     str += '</ul><ul><div class="clear webnavTitle">更多精选</div>'
     for (var i = 0; i < moreData.length; i++) {
         str += `
         <li><a>${moreData[i]}</a></li>
         `
     }
     webnav.innerHTML = str
 }
 var timerId1
 webnav.previousElementSibling.onmouseout = webnav.onmouseout = function () {
     timerId1 = setTimeout(() => {
         webnav.style.display = 'none'
         webnav.previousElementSibling.parentElement.style.background = '#E3E4E5'
     }, 100)
 }
 webnav.onmouseover = function () {
     clearTimeout(timerId1)
     webnav.style.display = 'block'
 }
 // 放大镜功能
//放大镜功能
function Zoom(){
    this.middle=document.querySelector('.middle')
    this.big=document.querySelector('.big')
    this.shade=document.querySelector('.shade')
    this.small=document.querySelector('.small')
    this.bigImg=document.querySelector('.big img')
    this.middleImg=document.querySelector('.middle>img')
}
Zoom.prototype.move=function(){
    //点击小图切换选框
    for(let i=0;i<this.small.children.length;i++){
        this.small.children[i].onclick=()=>{
            for(let j=0;j<this.small.children.length;j++){
                this.small.children[j].className=''
            }
            this.small.children[i].className='active'
            var path = this.small.children[i].firstElementChild.getAttribute('src')
            this.middleImg.setAttribute('src',path)
            this.bigImg.setAttribute('src',path)
        }            
    }
    //鼠标移动遮罩跟随
    this.middle.onmouseover=()=>{
        this.big.style.display='block'
        this.shade.style.display='block'
        this.middle.onmousemove=()=>{
            // 鼠标移入大图消失
            var e = window.event
            var x = e.pageX
            var y = e.pageY
            var l = x - this.shade.clientWidth/2-this.middle.offsetLeft
            var t = y - this.shade.clientHeight/2-this.middle.offsetTop
            //限制遮罩运动范围
            if(l<0) l=0
            if(t<0) t=0
            if(l>this.middle.offsetWidth-this.shade.offsetWidth) l=this.middle.offsetWidth-this.shade.offsetWidth
            if(t>this.middle.offsetHeight-this.shade.offsetHeight) t=this.middle.offsetHeight-this.shade.offsetHeight
            this.shade.style.top=t+'px'
            this.shade.style.left=l+'px'
            //鼠标移动大图大小跟随变化
            this.bigImg.style.left=-l/this.middle.offsetWidth*this.bigImg.offsetWidth+'px'
            this.bigImg.style.top=-t/this.middle.offsetHeight*this.bigImg.offsetHeight+'px'
        }
                //鼠标划出大图消失
        this.middle.onmouseout=()=>{
            this.shade.style.display='none'
            this.big.style.display='none'
        }
    }
}


// 商品扩展标题
$('.goods_extend_tit li').on('click',function(){
    $(this).siblings().removeClass('goods_extend_tit_active')
    $(this).attr('class','goods_extend_tit_active')
})


